{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Polynomial features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from sklearn import set_config\n",
    "from sklearn.preprocessing import PolynomialFeatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "set_config(transform_output=\"pandas\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>var</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     var\n",
       "0    0.0\n",
       "1    1.0\n",
       "2    2.0\n",
       "3    3.0\n",
       "4    4.0\n",
       "5    5.0\n",
       "6    6.0\n",
       "7    7.0\n",
       "8    8.0\n",
       "9    9.0\n",
       "10  10.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# toy dataframe with values 1 to 10\n",
    "\n",
    "df = pd.DataFrame(np.linspace(0, 10, 11), columns=[\"var\"])\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>var</th>\n",
       "      <th>var^2</th>\n",
       "      <th>var^3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>125.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>216.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>343.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>512.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>81.0</td>\n",
       "      <td>729.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     var  var^2   var^3\n",
       "0    0.0    0.0     0.0\n",
       "1    1.0    1.0     1.0\n",
       "2    2.0    4.0     8.0\n",
       "3    3.0    9.0    27.0\n",
       "4    4.0   16.0    64.0\n",
       "5    5.0   25.0   125.0\n",
       "6    6.0   36.0   216.0\n",
       "7    7.0   49.0   343.0\n",
       "8    8.0   64.0   512.0\n",
       "9    9.0   81.0   729.0\n",
       "10  10.0  100.0  1000.0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's create features up to a 3rd degree polynomial\n",
    "\n",
    "poly = PolynomialFeatures(degree=3, interaction_only=False, include_bias=False)\n",
    "\n",
    "dft = poly.fit_transform(df)\n",
    "\n",
    "dft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['var', 'var^2', 'var^3'], dtype=object)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the names of the returned features\n",
    "\n",
    "poly.get_feature_names_out()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.rcParams[\"figure.dpi\"] = 450"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEGCAYAAACUzrmNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAxgUlEQVR4nO3dd3xV9f3H8dfnJiGLvSFsWbKEEAHrqAMt4kArFvtrK1qqqCC4QWvrqFrQCmJRLBUpWusoaqXOIiJKHWwZQgVBJGGGnT3u5/fHOQk3ISGXJPee3OTz7CM9+5z3vZLzyVnfI6qKMcYYcyI+rwMYY4yp+axYGGOMqZAVC2OMMRWyYmGMMaZCViyMMcZUKNrrAKHQvHlz7dSpk9cxjDEmoqxcuTJdVVuUNa1WFotOnTqxYsUKr2MYY0xEEZHt5U2z01DGGGMqZMXCGGNMhaxYGGOMqVCtvGZRlvz8fFJTU8nJyfE6iqfi4uJo164dMTExXkcxxkSQOlMsUlNTadCgAZ06dUJEvI7jCVVl//79pKam0rlzZ6/jGGMi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DeQFTI1VdW4X1NAJ2qaofp1HIwGsOg9xWlH04RWlpqWUXASNFpCUUv7u5Y5DbNXWMFQtTq7ivif0bsAznrX/Pq+rqCpZZjnOaai3wPrAOOHwSm30c+KOIrCb4o/X5OE2kv17F9TwLjBaRr4GelDwCWQ7MxGmaexvwVuCCqvoNcD/wHxFZCywE2gS5XVPHWKuzxuC8LVBVM0QkAfgUuLHo/eTGGLtmYUyR2SLSC4jDOY9vhcKYAHZkYYwxpkJ2zcIYY0yFrFgYY4ypkBULY4wxFbJiYYwxpkJWLIwxxlTo/wHiD/3TfK7MsQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot poly features against original variable\n",
    "\n",
    "plt.plot(df[\"var\"], dft)\n",
    "plt.legend(dft.columns)\n",
    "plt.xlabel(\"original variable\")\n",
    "plt.ylabel(\"new variables\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>var</th>\n",
       "      <th>col</th>\n",
       "      <th>feat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>1.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "      <td>3.5</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>4.5</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     var  col  feat\n",
       "0    0.0  0.0   0.0\n",
       "1    1.0  0.5   0.5\n",
       "2    2.0  1.0   1.0\n",
       "3    3.0  1.5   1.5\n",
       "4    4.0  2.0   2.0\n",
       "5    5.0  2.5   2.5\n",
       "6    6.0  3.0   3.0\n",
       "7    7.0  3.5   3.5\n",
       "8    8.0  4.0   4.0\n",
       "9    9.0  4.5   4.5\n",
       "10  10.0  5.0   5.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's add another column\n",
    "\n",
    "df[\"col\"] = np.linspace(0, 5, 11)\n",
    "df[\"feat\"] = np.linspace(0, 5, 11)\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>var</th>\n",
       "      <th>col</th>\n",
       "      <th>feat</th>\n",
       "      <th>var col</th>\n",
       "      <th>var feat</th>\n",
       "      <th>col feat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>1.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>2.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.5</td>\n",
       "      <td>12.5</td>\n",
       "      <td>12.5</td>\n",
       "      <td>6.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>9.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "      <td>3.5</td>\n",
       "      <td>3.5</td>\n",
       "      <td>24.5</td>\n",
       "      <td>24.5</td>\n",
       "      <td>12.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>16.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>4.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>40.5</td>\n",
       "      <td>40.5</td>\n",
       "      <td>20.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>25.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     var  col  feat  var col  var feat  col feat\n",
       "0    0.0  0.0   0.0      0.0       0.0      0.00\n",
       "1    1.0  0.5   0.5      0.5       0.5      0.25\n",
       "2    2.0  1.0   1.0      2.0       2.0      1.00\n",
       "3    3.0  1.5   1.5      4.5       4.5      2.25\n",
       "4    4.0  2.0   2.0      8.0       8.0      4.00\n",
       "5    5.0  2.5   2.5     12.5      12.5      6.25\n",
       "6    6.0  3.0   3.0     18.0      18.0      9.00\n",
       "7    7.0  3.5   3.5     24.5      24.5     12.25\n",
       "8    8.0  4.0   4.0     32.0      32.0     16.00\n",
       "9    9.0  4.5   4.5     40.5      40.5     20.25\n",
       "10  10.0  5.0   5.0     50.0      50.0     25.00"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's create features up to a 3rd degree polynomial\n",
    "\n",
    "poly = PolynomialFeatures(degree=2, interaction_only=True, include_bias=False)\n",
    "\n",
    "dft = poly.fit_transform(df)\n",
    "\n",
    "dft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['var', 'col', 'feat', 'var col', 'var feat', 'col feat'],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly.get_feature_names_out()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>var</th>\n",
       "      <th>col</th>\n",
       "      <th>feat</th>\n",
       "      <th>var col</th>\n",
       "      <th>var feat</th>\n",
       "      <th>col feat</th>\n",
       "      <th>var col feat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>2.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>1.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>2.25</td>\n",
       "      <td>6.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.00</td>\n",
       "      <td>16.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5.0</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.5</td>\n",
       "      <td>12.5</td>\n",
       "      <td>12.5</td>\n",
       "      <td>6.25</td>\n",
       "      <td>31.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>54.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "      <td>3.5</td>\n",
       "      <td>3.5</td>\n",
       "      <td>24.5</td>\n",
       "      <td>24.5</td>\n",
       "      <td>12.25</td>\n",
       "      <td>85.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>16.00</td>\n",
       "      <td>128.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>4.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>40.5</td>\n",
       "      <td>40.5</td>\n",
       "      <td>20.25</td>\n",
       "      <td>182.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>25.00</td>\n",
       "      <td>250.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     var  col  feat  var col  var feat  col feat  var col feat\n",
       "0    0.0  0.0   0.0      0.0       0.0      0.00          0.00\n",
       "1    1.0  0.5   0.5      0.5       0.5      0.25          0.25\n",
       "2    2.0  1.0   1.0      2.0       2.0      1.00          2.00\n",
       "3    3.0  1.5   1.5      4.5       4.5      2.25          6.75\n",
       "4    4.0  2.0   2.0      8.0       8.0      4.00         16.00\n",
       "5    5.0  2.5   2.5     12.5      12.5      6.25         31.25\n",
       "6    6.0  3.0   3.0     18.0      18.0      9.00         54.00\n",
       "7    7.0  3.5   3.5     24.5      24.5     12.25         85.75\n",
       "8    8.0  4.0   4.0     32.0      32.0     16.00        128.00\n",
       "9    9.0  4.5   4.5     40.5      40.5     20.25        182.25\n",
       "10  10.0  5.0   5.0     50.0      50.0     25.00        250.00"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's create features up to a 3rd degree polynomial\n",
    "\n",
    "poly = PolynomialFeatures(degree=3, interaction_only=True, include_bias=False)\n",
    "\n",
    "dft = poly.fit_transform(df)\n",
    "\n",
    "dft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['var', 'col', 'feat', 'var col', 'var feat', 'col feat',\n",
       "       'var col feat'], dtype=object)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly.get_feature_names_out()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_breast_cancer\n",
    "from sklearn.compose import ColumnTransformer\n",
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean radius</th>\n",
       "      <th>mean texture</th>\n",
       "      <th>mean perimeter</th>\n",
       "      <th>mean area</th>\n",
       "      <th>mean smoothness</th>\n",
       "      <th>mean compactness</th>\n",
       "      <th>mean concavity</th>\n",
       "      <th>mean concave points</th>\n",
       "      <th>mean symmetry</th>\n",
       "      <th>mean fractal dimension</th>\n",
       "      <th>...</th>\n",
       "      <th>worst radius</th>\n",
       "      <th>worst texture</th>\n",
       "      <th>worst perimeter</th>\n",
       "      <th>worst area</th>\n",
       "      <th>worst smoothness</th>\n",
       "      <th>worst compactness</th>\n",
       "      <th>worst concavity</th>\n",
       "      <th>worst concave points</th>\n",
       "      <th>worst symmetry</th>\n",
       "      <th>worst fractal dimension</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>478</th>\n",
       "      <td>11.490</td>\n",
       "      <td>14.59</td>\n",
       "      <td>73.99</td>\n",
       "      <td>404.9</td>\n",
       "      <td>0.10460</td>\n",
       "      <td>0.08228</td>\n",
       "      <td>0.05308</td>\n",
       "      <td>0.01969</td>\n",
       "      <td>0.1779</td>\n",
       "      <td>0.06574</td>\n",
       "      <td>...</td>\n",
       "      <td>12.40</td>\n",
       "      <td>21.90</td>\n",
       "      <td>82.04</td>\n",
       "      <td>467.6</td>\n",
       "      <td>0.1352</td>\n",
       "      <td>0.2010</td>\n",
       "      <td>0.25960</td>\n",
       "      <td>0.07431</td>\n",
       "      <td>0.2941</td>\n",
       "      <td>0.09180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>303</th>\n",
       "      <td>10.490</td>\n",
       "      <td>18.61</td>\n",
       "      <td>66.86</td>\n",
       "      <td>334.3</td>\n",
       "      <td>0.10680</td>\n",
       "      <td>0.06678</td>\n",
       "      <td>0.02297</td>\n",
       "      <td>0.01780</td>\n",
       "      <td>0.1482</td>\n",
       "      <td>0.06600</td>\n",
       "      <td>...</td>\n",
       "      <td>11.06</td>\n",
       "      <td>24.54</td>\n",
       "      <td>70.76</td>\n",
       "      <td>375.4</td>\n",
       "      <td>0.1413</td>\n",
       "      <td>0.1044</td>\n",
       "      <td>0.08423</td>\n",
       "      <td>0.06528</td>\n",
       "      <td>0.2213</td>\n",
       "      <td>0.07842</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>12.250</td>\n",
       "      <td>17.94</td>\n",
       "      <td>78.27</td>\n",
       "      <td>460.3</td>\n",
       "      <td>0.08654</td>\n",
       "      <td>0.06679</td>\n",
       "      <td>0.03885</td>\n",
       "      <td>0.02331</td>\n",
       "      <td>0.1970</td>\n",
       "      <td>0.06228</td>\n",
       "      <td>...</td>\n",
       "      <td>13.59</td>\n",
       "      <td>25.22</td>\n",
       "      <td>86.60</td>\n",
       "      <td>564.2</td>\n",
       "      <td>0.1217</td>\n",
       "      <td>0.1788</td>\n",
       "      <td>0.19430</td>\n",
       "      <td>0.08211</td>\n",
       "      <td>0.3113</td>\n",
       "      <td>0.08132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>186</th>\n",
       "      <td>18.310</td>\n",
       "      <td>18.58</td>\n",
       "      <td>118.60</td>\n",
       "      <td>1041.0</td>\n",
       "      <td>0.08588</td>\n",
       "      <td>0.08468</td>\n",
       "      <td>0.08169</td>\n",
       "      <td>0.05814</td>\n",
       "      <td>0.1621</td>\n",
       "      <td>0.05425</td>\n",
       "      <td>...</td>\n",
       "      <td>21.31</td>\n",
       "      <td>26.36</td>\n",
       "      <td>139.20</td>\n",
       "      <td>1410.0</td>\n",
       "      <td>0.1234</td>\n",
       "      <td>0.2445</td>\n",
       "      <td>0.35380</td>\n",
       "      <td>0.15710</td>\n",
       "      <td>0.3206</td>\n",
       "      <td>0.06938</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>6.981</td>\n",
       "      <td>13.43</td>\n",
       "      <td>43.79</td>\n",
       "      <td>143.5</td>\n",
       "      <td>0.11700</td>\n",
       "      <td>0.07568</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.1930</td>\n",
       "      <td>0.07818</td>\n",
       "      <td>...</td>\n",
       "      <td>7.93</td>\n",
       "      <td>19.54</td>\n",
       "      <td>50.41</td>\n",
       "      <td>185.2</td>\n",
       "      <td>0.1584</td>\n",
       "      <td>0.1202</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.2932</td>\n",
       "      <td>0.09382</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     mean radius  mean texture  mean perimeter  mean area  mean smoothness  \\\n",
       "478       11.490         14.59           73.99      404.9          0.10460   \n",
       "303       10.490         18.61           66.86      334.3          0.10680   \n",
       "155       12.250         17.94           78.27      460.3          0.08654   \n",
       "186       18.310         18.58          118.60     1041.0          0.08588   \n",
       "101        6.981         13.43           43.79      143.5          0.11700   \n",
       "\n",
       "     mean compactness  mean concavity  mean concave points  mean symmetry  \\\n",
       "478           0.08228         0.05308              0.01969         0.1779   \n",
       "303           0.06678         0.02297              0.01780         0.1482   \n",
       "155           0.06679         0.03885              0.02331         0.1970   \n",
       "186           0.08468         0.08169              0.05814         0.1621   \n",
       "101           0.07568         0.00000              0.00000         0.1930   \n",
       "\n",
       "     mean fractal dimension  ...  worst radius  worst texture  \\\n",
       "478                 0.06574  ...         12.40          21.90   \n",
       "303                 0.06600  ...         11.06          24.54   \n",
       "155                 0.06228  ...         13.59          25.22   \n",
       "186                 0.05425  ...         21.31          26.36   \n",
       "101                 0.07818  ...          7.93          19.54   \n",
       "\n",
       "     worst perimeter  worst area  worst smoothness  worst compactness  \\\n",
       "478            82.04       467.6            0.1352             0.2010   \n",
       "303            70.76       375.4            0.1413             0.1044   \n",
       "155            86.60       564.2            0.1217             0.1788   \n",
       "186           139.20      1410.0            0.1234             0.2445   \n",
       "101            50.41       185.2            0.1584             0.1202   \n",
       "\n",
       "     worst concavity  worst concave points  worst symmetry  \\\n",
       "478          0.25960               0.07431          0.2941   \n",
       "303          0.08423               0.06528          0.2213   \n",
       "155          0.19430               0.08211          0.3113   \n",
       "186          0.35380               0.15710          0.3206   \n",
       "101          0.00000               0.00000          0.2932   \n",
       "\n",
       "     worst fractal dimension  \n",
       "478                  0.09180  \n",
       "303                  0.07842  \n",
       "155                  0.08132  \n",
       "186                  0.06938  \n",
       "101                  0.09382  \n",
       "\n",
       "[5 rows x 30 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load the breast cancer dataset from sklearn\n",
    "data = load_breast_cancer()\n",
    "\n",
    "# create a dataframe with the independent variables\n",
    "df = pd.DataFrame(data.data, columns=data.feature_names)\n",
    "\n",
    "# let's separate into training and testing set\n",
    "X_train, X_test, y_train, y_test = train_test_split(\n",
    "    df, data.target, test_size=0.3, random_state=0\n",
    ")\n",
    "\n",
    "# display\n",
    "X_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# features to combine\n",
    "\n",
    "features = [\"mean smoothness\", \"mean compactness\", \"mean concavity\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set up the polynomial expansion transformer\n",
    "\n",
    "poly = PolynomialFeatures(degree=3, interaction_only=False, include_bias=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "ct = ColumnTransformer([(\"poly\", poly, features)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {\n",
       "  /* Definition of color scheme common for light and dark mode */\n",
       "  --sklearn-color-text: black;\n",
       "  --sklearn-color-line: gray;\n",
       "  /* Definition of color scheme for unfitted estimators */\n",
       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
       "  --sklearn-color-unfitted-level-3: chocolate;\n",
       "  /* Definition of color scheme for fitted estimators */\n",
       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
       "  --sklearn-color-fitted-level-1: #d4ebff;\n",
       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
       "\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-icon: #696969;\n",
       "\n",
       "  @media (prefers-color-scheme: dark) {\n",
       "    /* Redefinition of color scheme for dark theme */\n",
       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-icon: #878787;\n",
       "  }\n",
       "}\n",
       "\n",
       "#sk-container-id-1 {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip: rect(1px 1px 1px 1px);\n",
       "  clip: rect(1px, 1px, 1px, 1px);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-dashed-wrapped {\n",
       "  border: 1px dashed var(--sklearn-color-line);\n",
       "  margin: 0 0.4em 0.5em 0.4em;\n",
       "  box-sizing: border-box;\n",
       "  padding-bottom: 0.4em;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-container {\n",
       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
       "     so we also need the `!important` here to be able to override the\n",
       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
       "  display: inline-block !important;\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-text-repr-fallback {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       "div.sk-parallel-item,\n",
       "div.sk-serial,\n",
       "div.sk-item {\n",
       "  /* draw centered vertical line to link estimators */\n",
       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
       "  background-size: 2px 100%;\n",
       "  background-repeat: no-repeat;\n",
       "  background-position: center center;\n",
       "}\n",
       "\n",
       "/* Parallel-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item::after {\n",
       "  content: \"\";\n",
       "  width: 100%;\n",
       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
       "  flex-grow: 1;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel {\n",
       "  display: flex;\n",
       "  align-items: stretch;\n",
       "  justify-content: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-serial {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "  align-items: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  padding-right: 1em;\n",
       "  padding-left: 1em;\n",
       "}\n",
       "\n",
       "\n",
       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
       "clickable and can be expanded/collapsed.\n",
       "- Pipeline and ColumnTransformer use this feature and define the default style\n",
       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
       "*/\n",
       "\n",
       "/* Pipeline and ColumnTransformer style (default) */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable {\n",
       "  /* Default theme specific background. It is overwritten whether we have a\n",
       "  specific estimator or a Pipeline/ColumnTransformer */\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "/* Toggleable label */\n",
       "#sk-container-id-1 label.sk-toggleable__label {\n",
       "  cursor: pointer;\n",
       "  display: block;\n",
       "  width: 100%;\n",
       "  margin-bottom: 0;\n",
       "  padding: 0.5em;\n",
       "  box-sizing: border-box;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
       "  /* Arrow on the left of the label */\n",
       "  content: \"▸\";\n",
       "  float: left;\n",
       "  margin-right: 0.25em;\n",
       "  color: var(--sklearn-color-icon);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content {\n",
       "  max-height: 0;\n",
       "  max-width: 0;\n",
       "  overflow: hidden;\n",
       "  text-align: left;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content pre {\n",
       "  margin: 0.2em;\n",
       "  border-radius: 0.25em;\n",
       "  color: var(--sklearn-color-text);\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
       "  /* Expand drop-down */\n",
       "  max-height: 200px;\n",
       "  max-width: 100%;\n",
       "  overflow: auto;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator-specific style */\n",
       "\n",
       "/* Colorize estimator box */\n",
       "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  /* The background is the default theme color */\n",
       "  color: var(--sklearn-color-text-on-default-background);\n",
       "}\n",
       "\n",
       "/* On hover, darken the color of the background */\n",
       "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "/* Label box, darken color on hover, fitted */\n",
       "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator label */\n",
       "\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  display: inline-block;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       "#sk-container-id-1 div.sk-estimator {\n",
       "  font-family: monospace;\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: 0.25em;\n",
       "  box-sizing: border-box;\n",
       "  margin-bottom: 0.5em;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       "#sk-container-id-1 div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
       "\n",
       "/* Common style for \"i\" and \"?\" */\n",
       "\n",
       ".sk-estimator-doc-link,\n",
       "a:link.sk-estimator-doc-link,\n",
       "a:visited.sk-estimator-doc-link {\n",
       "  float: right;\n",
       "  font-size: smaller;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1em;\n",
       "  height: 1em;\n",
       "  width: 1em;\n",
       "  text-decoration: none !important;\n",
       "  margin-left: 1ex;\n",
       "  /* unfitted */\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted,\n",
       "a:link.sk-estimator-doc-link.fitted,\n",
       "a:visited.sk-estimator-doc-link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "/* Span, style for the box shown on hovering the info icon */\n",
       ".sk-estimator-doc-link span {\n",
       "  display: none;\n",
       "  z-index: 9999;\n",
       "  position: relative;\n",
       "  font-weight: normal;\n",
       "  right: .2ex;\n",
       "  padding: .5ex;\n",
       "  margin: .5ex;\n",
       "  width: min-content;\n",
       "  min-width: 20ex;\n",
       "  max-width: 50ex;\n",
       "  color: var(--sklearn-color-text);\n",
       "  box-shadow: 2pt 2pt 4pt #999;\n",
       "  /* unfitted */\n",
       "  background: var(--sklearn-color-unfitted-level-0);\n",
       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted span {\n",
       "  /* fitted */\n",
       "  background: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link:hover span {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link {\n",
       "  float: right;\n",
       "  font-size: 1rem;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1rem;\n",
       "  height: 1rem;\n",
       "  width: 1rem;\n",
       "  text-decoration: none;\n",
       "  /* unfitted */\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "#sk-container-id-1 a.estimator_doc_link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>ColumnTransformer(transformers=[(&#x27;poly&#x27;,\n",
       "                                 PolynomialFeatures(degree=3,\n",
       "                                                    include_bias=False),\n",
       "                                 [&#x27;mean smoothness&#x27;, &#x27;mean compactness&#x27;,\n",
       "                                  &#x27;mean concavity&#x27;])])</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item sk-dashed-wrapped\"><div class=\"sk-label-container\"><div class=\"sk-label fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" ><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;&nbsp;ColumnTransformer<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.compose.ColumnTransformer.html\">?<span>Documentation for ColumnTransformer</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>ColumnTransformer(transformers=[(&#x27;poly&#x27;,\n",
       "                                 PolynomialFeatures(degree=3,\n",
       "                                                    include_bias=False),\n",
       "                                 [&#x27;mean smoothness&#x27;, &#x27;mean compactness&#x27;,\n",
       "                                  &#x27;mean concavity&#x27;])])</pre></div> </div></div><div class=\"sk-parallel\"><div class=\"sk-parallel-item\"><div class=\"sk-item\"><div class=\"sk-label-container\"><div class=\"sk-label fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" ><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">poly</label><div class=\"sk-toggleable__content fitted\"><pre>[&#x27;mean smoothness&#x27;, &#x27;mean compactness&#x27;, &#x27;mean concavity&#x27;]</pre></div> </div></div><div class=\"sk-serial\"><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" ><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;PolynomialFeatures<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.preprocessing.PolynomialFeatures.html\">?<span>Documentation for PolynomialFeatures</span></a></label><div class=\"sk-toggleable__content fitted\"><pre>PolynomialFeatures(degree=3, include_bias=False)</pre></div> </div></div></div></div></div></div></div></div></div>"
      ],
      "text/plain": [
       "ColumnTransformer(transformers=[('poly',\n",
       "                                 PolynomialFeatures(degree=3,\n",
       "                                                    include_bias=False),\n",
       "                                 ['mean smoothness', 'mean compactness',\n",
       "                                  'mean concavity'])])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ct.fit(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create the new features\n",
    "\n",
    "train_t = ct.transform(X_train)\n",
    "test_t = ct.transform(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['poly__mean smoothness', 'poly__mean compactness',\n",
       "       'poly__mean concavity', 'poly__mean smoothness^2',\n",
       "       'poly__mean smoothness mean compactness',\n",
       "       'poly__mean smoothness mean concavity', 'poly__mean compactness^2',\n",
       "       'poly__mean compactness mean concavity', 'poly__mean concavity^2',\n",
       "       'poly__mean smoothness^3',\n",
       "       'poly__mean smoothness^2 mean compactness',\n",
       "       'poly__mean smoothness^2 mean concavity',\n",
       "       'poly__mean smoothness mean compactness^2',\n",
       "       'poly__mean smoothness mean compactness mean concavity',\n",
       "       'poly__mean smoothness mean concavity^2',\n",
       "       'poly__mean compactness^3',\n",
       "       'poly__mean compactness^2 mean concavity',\n",
       "       'poly__mean compactness mean concavity^2',\n",
       "       'poly__mean concavity^3'], dtype=object)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get the name of the created features\n",
    "\n",
    "ct.get_feature_names_out()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>poly__mean smoothness</th>\n",
       "      <th>poly__mean compactness</th>\n",
       "      <th>poly__mean concavity</th>\n",
       "      <th>poly__mean smoothness^2</th>\n",
       "      <th>poly__mean smoothness mean compactness</th>\n",
       "      <th>poly__mean smoothness mean concavity</th>\n",
       "      <th>poly__mean compactness^2</th>\n",
       "      <th>poly__mean compactness mean concavity</th>\n",
       "      <th>poly__mean concavity^2</th>\n",
       "      <th>poly__mean smoothness^3</th>\n",
       "      <th>poly__mean smoothness^2 mean compactness</th>\n",
       "      <th>poly__mean smoothness^2 mean concavity</th>\n",
       "      <th>poly__mean smoothness mean compactness^2</th>\n",
       "      <th>poly__mean smoothness mean compactness mean concavity</th>\n",
       "      <th>poly__mean smoothness mean concavity^2</th>\n",
       "      <th>poly__mean compactness^3</th>\n",
       "      <th>poly__mean compactness^2 mean concavity</th>\n",
       "      <th>poly__mean compactness mean concavity^2</th>\n",
       "      <th>poly__mean concavity^3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>512</th>\n",
       "      <td>0.11060</td>\n",
       "      <td>0.14690</td>\n",
       "      <td>0.14450</td>\n",
       "      <td>0.012232</td>\n",
       "      <td>0.016247</td>\n",
       "      <td>0.015982</td>\n",
       "      <td>0.021580</td>\n",
       "      <td>0.021227</td>\n",
       "      <td>0.020880</td>\n",
       "      <td>0.001353</td>\n",
       "      <td>0.001797</td>\n",
       "      <td>0.001768</td>\n",
       "      <td>0.002387</td>\n",
       "      <td>0.002348</td>\n",
       "      <td>0.002309</td>\n",
       "      <td>0.003170</td>\n",
       "      <td>0.003118</td>\n",
       "      <td>0.003067</td>\n",
       "      <td>0.003017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>457</th>\n",
       "      <td>0.08791</td>\n",
       "      <td>0.05205</td>\n",
       "      <td>0.02772</td>\n",
       "      <td>0.007728</td>\n",
       "      <td>0.004576</td>\n",
       "      <td>0.002437</td>\n",
       "      <td>0.002709</td>\n",
       "      <td>0.001443</td>\n",
       "      <td>0.000768</td>\n",
       "      <td>0.000679</td>\n",
       "      <td>0.000402</td>\n",
       "      <td>0.000214</td>\n",
       "      <td>0.000238</td>\n",
       "      <td>0.000127</td>\n",
       "      <td>0.000068</td>\n",
       "      <td>0.000141</td>\n",
       "      <td>0.000075</td>\n",
       "      <td>0.000040</td>\n",
       "      <td>0.000021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>0.07966</td>\n",
       "      <td>0.05581</td>\n",
       "      <td>0.02087</td>\n",
       "      <td>0.006346</td>\n",
       "      <td>0.004446</td>\n",
       "      <td>0.001663</td>\n",
       "      <td>0.003115</td>\n",
       "      <td>0.001165</td>\n",
       "      <td>0.000436</td>\n",
       "      <td>0.000505</td>\n",
       "      <td>0.000354</td>\n",
       "      <td>0.000132</td>\n",
       "      <td>0.000248</td>\n",
       "      <td>0.000093</td>\n",
       "      <td>0.000035</td>\n",
       "      <td>0.000174</td>\n",
       "      <td>0.000065</td>\n",
       "      <td>0.000024</td>\n",
       "      <td>0.000009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>0.06576</td>\n",
       "      <td>0.05220</td>\n",
       "      <td>0.02475</td>\n",
       "      <td>0.004324</td>\n",
       "      <td>0.003433</td>\n",
       "      <td>0.001628</td>\n",
       "      <td>0.002725</td>\n",
       "      <td>0.001292</td>\n",
       "      <td>0.000613</td>\n",
       "      <td>0.000284</td>\n",
       "      <td>0.000226</td>\n",
       "      <td>0.000107</td>\n",
       "      <td>0.000179</td>\n",
       "      <td>0.000085</td>\n",
       "      <td>0.000040</td>\n",
       "      <td>0.000142</td>\n",
       "      <td>0.000067</td>\n",
       "      <td>0.000032</td>\n",
       "      <td>0.000015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>0.08983</td>\n",
       "      <td>0.03766</td>\n",
       "      <td>0.02562</td>\n",
       "      <td>0.008069</td>\n",
       "      <td>0.003383</td>\n",
       "      <td>0.002301</td>\n",
       "      <td>0.001418</td>\n",
       "      <td>0.000965</td>\n",
       "      <td>0.000656</td>\n",
       "      <td>0.000725</td>\n",
       "      <td>0.000304</td>\n",
       "      <td>0.000207</td>\n",
       "      <td>0.000127</td>\n",
       "      <td>0.000087</td>\n",
       "      <td>0.000059</td>\n",
       "      <td>0.000053</td>\n",
       "      <td>0.000036</td>\n",
       "      <td>0.000025</td>\n",
       "      <td>0.000017</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     poly__mean smoothness  poly__mean compactness  poly__mean concavity  \\\n",
       "512                0.11060                 0.14690               0.14450   \n",
       "457                0.08791                 0.05205               0.02772   \n",
       "439                0.07966                 0.05581               0.02087   \n",
       "298                0.06576                 0.05220               0.02475   \n",
       "37                 0.08983                 0.03766               0.02562   \n",
       "\n",
       "     poly__mean smoothness^2  poly__mean smoothness mean compactness  \\\n",
       "512                 0.012232                                0.016247   \n",
       "457                 0.007728                                0.004576   \n",
       "439                 0.006346                                0.004446   \n",
       "298                 0.004324                                0.003433   \n",
       "37                  0.008069                                0.003383   \n",
       "\n",
       "     poly__mean smoothness mean concavity  poly__mean compactness^2  \\\n",
       "512                              0.015982                  0.021580   \n",
       "457                              0.002437                  0.002709   \n",
       "439                              0.001663                  0.003115   \n",
       "298                              0.001628                  0.002725   \n",
       "37                               0.002301                  0.001418   \n",
       "\n",
       "     poly__mean compactness mean concavity  poly__mean concavity^2  \\\n",
       "512                               0.021227                0.020880   \n",
       "457                               0.001443                0.000768   \n",
       "439                               0.001165                0.000436   \n",
       "298                               0.001292                0.000613   \n",
       "37                                0.000965                0.000656   \n",
       "\n",
       "     poly__mean smoothness^3  poly__mean smoothness^2 mean compactness  \\\n",
       "512                 0.001353                                  0.001797   \n",
       "457                 0.000679                                  0.000402   \n",
       "439                 0.000505                                  0.000354   \n",
       "298                 0.000284                                  0.000226   \n",
       "37                  0.000725                                  0.000304   \n",
       "\n",
       "     poly__mean smoothness^2 mean concavity  \\\n",
       "512                                0.001768   \n",
       "457                                0.000214   \n",
       "439                                0.000132   \n",
       "298                                0.000107   \n",
       "37                                 0.000207   \n",
       "\n",
       "     poly__mean smoothness mean compactness^2  \\\n",
       "512                                  0.002387   \n",
       "457                                  0.000238   \n",
       "439                                  0.000248   \n",
       "298                                  0.000179   \n",
       "37                                   0.000127   \n",
       "\n",
       "     poly__mean smoothness mean compactness mean concavity  \\\n",
       "512                                           0.002348       \n",
       "457                                           0.000127       \n",
       "439                                           0.000093       \n",
       "298                                           0.000085       \n",
       "37                                            0.000087       \n",
       "\n",
       "     poly__mean smoothness mean concavity^2  poly__mean compactness^3  \\\n",
       "512                                0.002309                  0.003170   \n",
       "457                                0.000068                  0.000141   \n",
       "439                                0.000035                  0.000174   \n",
       "298                                0.000040                  0.000142   \n",
       "37                                 0.000059                  0.000053   \n",
       "\n",
       "     poly__mean compactness^2 mean concavity  \\\n",
       "512                                 0.003118   \n",
       "457                                 0.000075   \n",
       "439                                 0.000065   \n",
       "298                                 0.000067   \n",
       "37                                  0.000036   \n",
       "\n",
       "     poly__mean compactness mean concavity^2  poly__mean concavity^3  \n",
       "512                                 0.003067                0.003017  \n",
       "457                                 0.000040                0.000021  \n",
       "439                                 0.000024                0.000009  \n",
       "298                                 0.000032                0.000015  \n",
       "37                                  0.000025                0.000017  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_t.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "from feature_engine.wrappers import SklearnTransformerWrapper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean radius</th>\n",
       "      <th>mean texture</th>\n",
       "      <th>mean perimeter</th>\n",
       "      <th>mean area</th>\n",
       "      <th>mean concave points</th>\n",
       "      <th>mean symmetry</th>\n",
       "      <th>mean fractal dimension</th>\n",
       "      <th>radius error</th>\n",
       "      <th>texture error</th>\n",
       "      <th>perimeter error</th>\n",
       "      <th>...</th>\n",
       "      <th>mean smoothness^3</th>\n",
       "      <th>mean smoothness^2 mean compactness</th>\n",
       "      <th>mean smoothness^2 mean concavity</th>\n",
       "      <th>mean smoothness mean compactness^2</th>\n",
       "      <th>mean smoothness mean compactness mean concavity</th>\n",
       "      <th>mean smoothness mean concavity^2</th>\n",
       "      <th>mean compactness^3</th>\n",
       "      <th>mean compactness^2 mean concavity</th>\n",
       "      <th>mean compactness mean concavity^2</th>\n",
       "      <th>mean concavity^3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>512</th>\n",
       "      <td>13.40</td>\n",
       "      <td>20.52</td>\n",
       "      <td>88.64</td>\n",
       "      <td>556.7</td>\n",
       "      <td>0.08172</td>\n",
       "      <td>0.2116</td>\n",
       "      <td>0.07325</td>\n",
       "      <td>0.3906</td>\n",
       "      <td>0.9306</td>\n",
       "      <td>3.093</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001353</td>\n",
       "      <td>0.001797</td>\n",
       "      <td>0.001768</td>\n",
       "      <td>0.002387</td>\n",
       "      <td>0.002348</td>\n",
       "      <td>0.002309</td>\n",
       "      <td>0.003170</td>\n",
       "      <td>0.003118</td>\n",
       "      <td>0.003067</td>\n",
       "      <td>0.003017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>457</th>\n",
       "      <td>13.21</td>\n",
       "      <td>25.25</td>\n",
       "      <td>84.10</td>\n",
       "      <td>537.9</td>\n",
       "      <td>0.02068</td>\n",
       "      <td>0.1619</td>\n",
       "      <td>0.05584</td>\n",
       "      <td>0.2084</td>\n",
       "      <td>1.3500</td>\n",
       "      <td>1.314</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000679</td>\n",
       "      <td>0.000402</td>\n",
       "      <td>0.000214</td>\n",
       "      <td>0.000238</td>\n",
       "      <td>0.000127</td>\n",
       "      <td>0.000068</td>\n",
       "      <td>0.000141</td>\n",
       "      <td>0.000075</td>\n",
       "      <td>0.000040</td>\n",
       "      <td>0.000021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>14.02</td>\n",
       "      <td>15.66</td>\n",
       "      <td>89.59</td>\n",
       "      <td>606.5</td>\n",
       "      <td>0.02652</td>\n",
       "      <td>0.1589</td>\n",
       "      <td>0.05586</td>\n",
       "      <td>0.2142</td>\n",
       "      <td>0.6549</td>\n",
       "      <td>1.606</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000505</td>\n",
       "      <td>0.000354</td>\n",
       "      <td>0.000132</td>\n",
       "      <td>0.000248</td>\n",
       "      <td>0.000093</td>\n",
       "      <td>0.000035</td>\n",
       "      <td>0.000174</td>\n",
       "      <td>0.000065</td>\n",
       "      <td>0.000024</td>\n",
       "      <td>0.000009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>14.26</td>\n",
       "      <td>18.17</td>\n",
       "      <td>91.22</td>\n",
       "      <td>633.1</td>\n",
       "      <td>0.01374</td>\n",
       "      <td>0.1635</td>\n",
       "      <td>0.05586</td>\n",
       "      <td>0.2300</td>\n",
       "      <td>0.6690</td>\n",
       "      <td>1.661</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000284</td>\n",
       "      <td>0.000226</td>\n",
       "      <td>0.000107</td>\n",
       "      <td>0.000179</td>\n",
       "      <td>0.000085</td>\n",
       "      <td>0.000040</td>\n",
       "      <td>0.000142</td>\n",
       "      <td>0.000067</td>\n",
       "      <td>0.000032</td>\n",
       "      <td>0.000015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>13.03</td>\n",
       "      <td>18.42</td>\n",
       "      <td>82.61</td>\n",
       "      <td>523.8</td>\n",
       "      <td>0.02923</td>\n",
       "      <td>0.1467</td>\n",
       "      <td>0.05863</td>\n",
       "      <td>0.1839</td>\n",
       "      <td>2.3420</td>\n",
       "      <td>1.170</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000725</td>\n",
       "      <td>0.000304</td>\n",
       "      <td>0.000207</td>\n",
       "      <td>0.000127</td>\n",
       "      <td>0.000087</td>\n",
       "      <td>0.000059</td>\n",
       "      <td>0.000053</td>\n",
       "      <td>0.000036</td>\n",
       "      <td>0.000025</td>\n",
       "      <td>0.000017</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 46 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     mean radius  mean texture  mean perimeter  mean area  \\\n",
       "512        13.40         20.52           88.64      556.7   \n",
       "457        13.21         25.25           84.10      537.9   \n",
       "439        14.02         15.66           89.59      606.5   \n",
       "298        14.26         18.17           91.22      633.1   \n",
       "37         13.03         18.42           82.61      523.8   \n",
       "\n",
       "     mean concave points  mean symmetry  mean fractal dimension  radius error  \\\n",
       "512              0.08172         0.2116                 0.07325        0.3906   \n",
       "457              0.02068         0.1619                 0.05584        0.2084   \n",
       "439              0.02652         0.1589                 0.05586        0.2142   \n",
       "298              0.01374         0.1635                 0.05586        0.2300   \n",
       "37               0.02923         0.1467                 0.05863        0.1839   \n",
       "\n",
       "     texture error  perimeter error  ...  mean smoothness^3  \\\n",
       "512         0.9306            3.093  ...           0.001353   \n",
       "457         1.3500            1.314  ...           0.000679   \n",
       "439         0.6549            1.606  ...           0.000505   \n",
       "298         0.6690            1.661  ...           0.000284   \n",
       "37          2.3420            1.170  ...           0.000725   \n",
       "\n",
       "     mean smoothness^2 mean compactness  mean smoothness^2 mean concavity  \\\n",
       "512                            0.001797                          0.001768   \n",
       "457                            0.000402                          0.000214   \n",
       "439                            0.000354                          0.000132   \n",
       "298                            0.000226                          0.000107   \n",
       "37                             0.000304                          0.000207   \n",
       "\n",
       "     mean smoothness mean compactness^2  \\\n",
       "512                            0.002387   \n",
       "457                            0.000238   \n",
       "439                            0.000248   \n",
       "298                            0.000179   \n",
       "37                             0.000127   \n",
       "\n",
       "     mean smoothness mean compactness mean concavity  \\\n",
       "512                                         0.002348   \n",
       "457                                         0.000127   \n",
       "439                                         0.000093   \n",
       "298                                         0.000085   \n",
       "37                                          0.000087   \n",
       "\n",
       "     mean smoothness mean concavity^2  mean compactness^3  \\\n",
       "512                          0.002309            0.003170   \n",
       "457                          0.000068            0.000141   \n",
       "439                          0.000035            0.000174   \n",
       "298                          0.000040            0.000142   \n",
       "37                           0.000059            0.000053   \n",
       "\n",
       "     mean compactness^2 mean concavity  mean compactness mean concavity^2  \\\n",
       "512                           0.003118                           0.003067   \n",
       "457                           0.000075                           0.000040   \n",
       "439                           0.000065                           0.000024   \n",
       "298                           0.000067                           0.000032   \n",
       "37                            0.000036                           0.000025   \n",
       "\n",
       "     mean concavity^3  \n",
       "512          0.003017  \n",
       "457          0.000021  \n",
       "439          0.000009  \n",
       "298          0.000015  \n",
       "37           0.000017  \n",
       "\n",
       "[5 rows x 46 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly = SklearnTransformerWrapper(\n",
    "    transformer=PolynomialFeatures(\n",
    "        degree=3, interaction_only=False, include_bias=False),\n",
    "    variables=features,\n",
    ")\n",
    "\n",
    "\n",
    "# create the new features\n",
    "train_t = poly.fit_transform(X_train)\n",
    "test_t = poly.transform(X_test)\n",
    "\n",
    "test_t.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fsml",
   "language": "python",
   "name": "fsml"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
